package com.tang.model.state.examination;

import org.springframework.messaging.Message;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;
import org.springframework.stereotype.Component;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/9/5 22:41
 * @Desc
 * @Remarks
 */
@Component("orderStateListener")
@WithStateMachine(name = "stateMachine")
public class ExamineListener {


    @OnTransition(source = "NO_APPOINTMENT", target = "APPOINTMENT")
    public boolean reserveTransition(Message<ExamineStatusActionEnum> message) {
        ExamineOrder order = (ExamineOrder) message.getHeaders().get("examineOrder");
        order.setStatus(ExamineStatusEnum.APPOINTMENT);
        System.out.println("预约，状态机反馈信息：" + message.getHeaders().toString());
        return true;
    }


    @OnTransition(source = "APPOINTMENT", target = "UNFILL_INFORMATION")
    public boolean takeNumberTransition(Message<ExamineStatusActionEnum> message) {
        ExamineOrder order = (ExamineOrder) message.getHeaders().get("examineOrder");
        order.setStatus(ExamineStatusEnum.UNFILL_INFORMATION);
        System.out.println("取号，状态机反馈信息：" + message.getHeaders().toString());
        return true;
    }

    @OnTransition(source = "UNFILL_INFORMATION", target = "PENDING_PAYMENT")
    public boolean entryInformationTransition(Message<ExamineStatusActionEnum> message) {
        ExamineOrder order = (ExamineOrder) message.getHeaders().get("examineOrder");
        order.setStatus(ExamineStatusEnum.PENDING_PAYMENT);
        System.out.println("录入信息，状态机反馈信息：" + message.getHeaders().toString());
        return true;
    }

    @OnTransition(source = "PENDING_PAYMENT", target = "UNCHECKED")
    public boolean paymentTransition(Message<ExamineStatusActionEnum> message) {
        ExamineOrder order = (ExamineOrder) message.getHeaders().get("examineOrder");
        order.setStatus(ExamineStatusEnum.UNCHECKED);
        System.out.println("支付，状态机反馈信息：" + message.getHeaders().toString());
        return true;
    }

    @OnTransition(source = "UNCHECKED", target = "PENDING_REPORT")
    public boolean examineTransition(Message<ExamineStatusActionEnum> message) {
        ExamineOrder order = (ExamineOrder) message.getHeaders().get("examineOrder");
        order.setStatus(ExamineStatusEnum.PENDING_REPORT);
        System.out.println("检查，状态机反馈信息：" + message.getHeaders().toString());
        return true;
    }

    @OnTransition(source = "PENDING_REPORT", target = "COMPLETED")
    public boolean publishedTransition(Message<ExamineStatusActionEnum> message) {
        ExamineOrder order = (ExamineOrder) message.getHeaders().get("examineOrder");
        order.setStatus(ExamineStatusEnum.COMPLETED);
        System.out.println("发布，状态机反馈信息：" + message.getHeaders().toString());
        return true;
    }

}
